package zky410;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {
    public static void main(String[] args) throws IOException {
        int len;
        int[] f = new int[10000];
        f[0] = 1;
        for(int i = 1;;i++){
            f[i] = 2*f[i-1];
            if(f[i]>1e9){
                len = i-1;
                break;
            }
        }
        BufferedReader sc = new BufferedReader(new InputStreamReader(System.in));
        int k = Integer.parseInt(sc.readLine());//表示k组数据
        int [][] res = new int[k][2];
        for(int i =0 ;i< k;i++){
            String[] str = sc.readLine().split(" ");
            for(int j =0;j<2;j++){
                res[i][j] = Integer.parseInt(str[j]);
            }
        }


        for(int i = 0;i<k;i++){
            int a = res[i][0];
            int b = res[i][1];
            if(a>b){
                int temp = a;
                a = b;
                b = temp;
            }
            int step = 0;
            int pp = 0;
            for(int j = 0;j<len;j++){
                if(a>=f[j]&&a<f[j+1]){
                    pp = j;
                    break;
                }
            }
            while(true){
                if(b>=f[pp]&&b<f[pp+1]){
                    break;
                }
                b /= 2;
                step++;
            }
            while(a!=b){
                a/=2;
                b/=2;
                step += 2;
            }
            System.out.println(step);
        }
    }

}